<?php
/**
 * NAME: todo
 * WHEN: OnMsg
 * PROVIDES: !todo
 * AUTOLOAD: true
 * DESCRIPTION: Menadżer zadań do wykonania.
 * VERSION: 0.1
 * UPDATE: http://update.tempaq2.blacksoft.eu/check.php
 * AUTHOR: blacksoft.eu
 */
exit();
 
//*function_start
	if ($data->messageex[0]=='!todo') {
		sqlite::create('todo',array(
			'id'=>'INT',
			'project'=>'VARCHAR',
			'todo'=>'VARCHAR',
		));
		
		if ($data->messageex[1]=="help") {
			$this->send("Dostępne polecenia:");
			$this->send("!todo list - wyświetla listę aktualnych projektów");
			$this->send("!todo nazwaprojektu - wyświetla liste zadań");
			$this->send("!todo nazwaprojektu add cos - dodaj nowy wpis do projektu");
			$this->send("!todo nazwaprojektu del id - usuwa z projektu wpis o id=id");
		} else if ($data->messageex[1]=="list") {
			//$table = new table('todo');
			$x = sqlite::fetchSQL('SELECT * FROM todo');
			$tab = array();
			if (is_array($x))
				foreach ($x as $z)
					$tab[$z['project']]=1;
			
			if (count($tab)) {
				$this->send("Lista Projektów:");
				$msg="";
				foreach ($tab as $k => $v)
					$msg.="$k; ";
				$this->send($msg);
				unset($msg);
			} else
				$this->send("Brak projektów.");
			//unset($table);
		} else if (!empty($data->messageex[1])) {
			//$table = new table('todo');
				$x = sqlite::fetchSQL('SELECT * FROM todo WHERE project="'.$data->messageex[1].'"');
				//$x=$table->select('project',$data->messageex[1],'=');
				if (empty($data->messageex[2])) {
					if (count($x)) {
						//mamy jakies rekordy dla projektu:)
						foreach ($x as $co) {
							$this->send("[".$co['id']."] => ".$co['todo']);
						}
					} else {
						$this->send("Nie znaleziono projektu ".$data->messageex[1]);
					}
				} else if (!empty($data->messageex[3])) {
					if ($data->messageex[2]=='add'&&$this->is_admin($data->nick)) {
						$id=$x[count($x)-1]['id']+1;
						sqlite::insert('todo',array(
							'id' => $id,
							'project' => $data->messageex[1],
							'todo' => substr($data->message,strpos($data->message, $data->messageex[3])))
						);
						
					} else if ($data->messageex[2]=='del'&&$this->is_admin($data->nick)) {
						$id = $data->messageex[3];
						$a = count($x);
						for($i=0;$i<$a;$i++) {
							if ($x[$i]['id']==$id) {
								sqlite::query('DELETE FROM todo WHERE project="'.$data->messageex[1].'"');
								unset($x[$i]);
								break;
							}
						}
						/*if ($table->update('project', $data->messageex[1],'=', $x)) {
							$this->send("Podczas usuwania wystąpił błąd!");
						}*/
					}
				}
			//unset($table);
		}
	}
//*function_end	
?>